<template>
	<rich-text class="notice-content" :nodes="format(html)"></rich-text>
</template>

<script>
	export default {
		data() {
			return {
				html: ''
			};
		},
		onShow() {
			this.html = getApp().globalData.announcement.content
			console.log(getApp().globalData.announcement.content);
			// this.replaceImgSrc(this.html)
		},
		methods: {
			replaceImgSrc(content) {
				const replaced = content.replace(/src=["']\.\.\/jeecg-boot/g,
					'src="https://sys.shengezhihuan.com/jeecg-boot');
				console.log(replaced);
				return replaced;
			},
			format(html) {
				var GRT = [
					// img 样式
					['img', "max-width:100%;height:auto;"],
				];
				for (let i = 0; i < GRT.length; i++) {
					html = html.replace(new RegExp('<' + GRT[i][0] + '>|<' + GRT[i][0] + ' (.*?)>', 'gi'), function(word) {
						// 分析 dom 上是否带有 style=""
						if (word.indexOf('style=') != -1) {
							var regIn = new RegExp('<' + GRT[i][0] + '(.*?)style="(.*?)"(.*?)(/?)>', 'gi');
							return word.replace(regIn, '<' + GRT[i][0] + '$1style="$2 ' + GRT[i][1] + '"$3$4>');
						} else {
							var regIn = new RegExp('<' + GRT[i][0] + '(.*?)(/?)>', 'gi');
							return word.replace(regIn, '<' + GRT[i][0] + '$1 style="' + GRT[i][1] + '$2">');
						}
					});
				}
				return html;
			},
		}
	}
</script>

<style lang="less">
	.notice-content {
		padding: 20rpx;
	}
</style>